package system

import (
	"bottle/global"
	"bottle/model/common/response"
	"bottle/model/system"
	systemReq "bottle/model/system/request"
	"bottle/utils"
	"github.com/gin-gonic/gin"
	"time"
)

type ReportApi struct{}

func (r *ReportApi) ReportUser(c *gin.Context) {
	var req systemReq.ReportUserRequest
	err := c.ShouldBind(&req)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = utils.Verify(req, utils.ReportUserVerify)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	var report system.Report
	err = global.GVA_DB.Where("user_id = ?", req.UserId).Where("operater_id = ?", req.OperaterID).First(&report).Error
	if report.ID != 0 {
		response.FailWithMessage("您已举报过该用户", c)
		return
	}
	report = system.Report{UserID: req.UserId, OperaterID: req.OperaterID, Type: req.Type, CreateTime: time.Now().Unix()}
	global.GVA_DB.Save(&report)
	response.Ok(c)
	return
}
